<?php

namespace App\Trip\Plane\Requests;

use App\Trip\Enums\Plane\PlaneProviders;
use Exception;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Http\Request;

class TicketPriceRequest implements Arrayable, CommonQueryInterface
{
    use TraitFromToDateRequest;

    private Request $req;

    /**
     * @throws Exception
     */
    public function __construct(Request $request)
    {
        $this->req = $request;
        if ($this->getFrom()->getCode() == $this->getTo()->getCode()) {
            throw new Exception('出发地和目的地不能相同');
        }
    }

    public function getProvider(): PlaneProviders
    {
        return PlaneProviders::from($this->req->input('provider'));
    }

    public function getFlightNo()
    {
        return $this->req->input('flight_no');
    }


    public function getOnlyDirect()
    {
        return $this->req->input('only_direct', 1);
    }

    public function getChildTypes()
    {
        return $this->req->input('child_types', []);
    }

    public function toArray(): array
    {
        return $this->req->toArray();
    }
}